package com.hlkj.warboot.module_wx.configurer.event;

import com.alibaba.fastjson.JSONObject;
import com.hlkj.warboot.configurer.util.LoggerUtil;
import com.hlkj.warboot.module_wx.entity.HkSeckillEntity;
import com.hlkj.warboot.module_wx.service.HkSeckillService;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.MessageFormat;

/**
 * @Description: 号卡秒杀监听
 * @Author: lixing
 * @Date: 2020/4/26 21:20
 */
@Component
@Async("asyncTaskExecutor")
public class HkSeckillListener {

    @Resource
    private HkSeckillService hkSeckillService;

    /*
     * @Description 秒杀记录入库
     * @Author lixing
     * @Date 2020/4/26 21:38
     * @Param [event]
     * @return void
     */
    @EventListener
    public void saveHkSeckill(HkSeckillEvent event) throws InterruptedException {
        HkSeckillEntity hkSeckillEntity = event.getHkSeckillEntity();
        if (!hkSeckillService.save(hkSeckillEntity)) {
            LoggerUtil.error(MessageFormat.format("号卡秒杀记录入库失败：{10}", JSONObject.toJSONString(hkSeckillEntity)));
        }
    }
}
